<?php

class lfMySQL
{
	
	public function __construct()
	{
	}
	
	public function __destruct()
	{

	}
	
	/**
	 * 创建一个到MySQL服务器的连接
	 *
	 * @param string $host
	 * @param string $user
	 * @param string $passwd
	 * @return res:connection
	 */
	public function Connect($host, $user, $passwd, $charSet = 'UTF8')
	{
		$this->host = $host;
		$this->user = $user;
		$this->passwd = $passwd;
		$this->charSet = $charSet;
		$this->connection = mysql_connect( $host, $user, $passwd);
		mysql_query( "SET NAMES UTF8", $this->connection);
		
		return $this->connection;
	}
	
	public function OpenDB($dbName)
	{
		if(! mysql_select_db( $dbName, $this->connection))
		{
			die( "DataBase $dbName does not exists");
		}
	}
	
	public function Execute($sql)
	{
		$this->sql = $sql;
		$result = mysql_query( $sql, $this->connection);
		
		return $result;
	}
	
	public function Close()
	{
		mysql_close($this->connection);
	}
	
	protected $connection = NULL;
	protected $dbName = '';
	protected $sql = '';
	protected $host = '';
	protected $user = '';
	protected $passwd = '';
	protected $charSet = '';
	protected $resRecordSet = NULL;
}
?>